<?php
/**
 * Model for performing CRUD operations on group permissions database table.
 * @package backend-roles/models
 * @category Model
 * 
 * @author Mark Angelo Angulo
 * @copyright (c) 2015
 */
class Permission_Model extends Crud {
    
    /**
     *  Constructor method.
     */
    function __construct()
    {
	parent::__construct();
        
        $cms = $this->cms;
        
        $this->table = $cms['db_prefix'] . 'ion_group_permissions';
    }
    
    /**
     * Edit Permission. Create it if it doesn't exist.
     * @access public
     * @param array $args An array containing filters to the database query.
     * @param array $record An array containing the information about the record.
     * @return array Returns the record.
     */
    public function update_permission($args = array(), $record = array())
    {
        $this->db->where($args);
        $data = $this->db->get($this->table)->row_array();

        if (empty($data))
        {
            // if it doesn't exist, we create it.
            $id = $this->insert($record);
            return $id;
        } else
        {
            // otherwise we update and return its ID.
            $id = $this->update($args, $record);
            return $data[$this->id];
        }
    }
}

/* End of file permission_model.php */
/* Location: ./application/roles/backend-permissions/models/permission_model.php */